package notes.java.juc.demo;

import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

// 线程池调度
// 可以对线程的延迟定时处理
public class K14_TestScheduledThreadPool {

	public static void main(String[] args) {
		// 创建一个线程调度线程池
		ScheduledExecutorService pool = Executors.newScheduledThreadPool(5);
		
		// 延迟2秒后执行
//		pool.schedule(new MyThread3(), 2, TimeUnit.SECONDS);
		
		// 延迟3秒后，每2秒执行一次
		pool.scheduleAtFixedRate(new MyThread3(), 3, 2, TimeUnit.SECONDS);
		
		
		// 关闭
//		pool.shutdown();
	}
}

class MyThread3 implements Runnable {
	@Override
	public void run() {
		System.out.println(Thread.currentThread().getName() + new Date());
	}
}